﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class RegistCategorias : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    String SQL, mssg;
    AdmiDatos.Service ad = new AdmiDatos.Service();
    System.Data.DataSet dst = new System.Data.DataSet();
    Formato1 vt = new Formato1();

    private void habilitarExiste()
    {
        BtnAgregar.Enabled = false;
        BtnEliminar.Enabled = true;
    }
    private void habilitarNuevo()
    {
        BtnAgregar.Enabled = true;
        BtnEliminar.Enabled = false;
    }
    private void deshabilitarBotones()
    {
        BtnAgregar.Enabled = false;
        BtnEliminar.Enabled = false;
        vt.LimpiartextBoxes(this);
    }

    protected void BtnAgregar_Click(object sender, EventArgs e)
    {
        try
        {
            SQL = "Insert into Categoria(CategoriaId,Descripcion)";
            SQL += " Values('" + TxtIdCategoria.Text + "','" + TxtDescripcion.Text + "')";
            ad.actualizaD(SQL, ref mssg);
            vt.MessageBox("Los Registros han sido ingresado exitosamente!", this);
            deshabilitarBotones();
        }
        catch (Exception ex)
        {
            vt.MessageBox(ex.Message, this);
        }
    }
   
    protected void BtnEliminar_Click(object sender, EventArgs e)
    {
        try
        {
        SQL = "Delete from Categoria Where CategoriaId = '" + TxtIdCategoria.Text + "'";
            
            ad.actualizaD(SQL, ref mssg);
            vt.MessageBox("Los Registros se han eliminado exitosamente!", this);
            deshabilitarBotones();
        }
        catch (Exception ex)
        {
            vt.MessageBox(ex.Message, this);
        }
    }
}